/**
 * Generali Solutions d'assurances - Tous droits réservés &copy; 2007 - 2010
 */
package fr.generali.accueilclient.utils.tuple;

import java.io.Serializable;

import org.apache.commons.lang.ObjectUtils;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.springframework.util.Assert;

/**
 * Couple
 * 
 * @param <O> premier élément
 * @param <T> second élément
 * @author Guillaume LANCELIN
 */
public class Couple<O, T> implements Serializable {

    /**
     * serialVersionUID
     */
    private static final long serialVersionUID = 7341645411285928581L;

    /**
     * Le premier élément
     */
    private final O one;

    /**
     * Le second élément
     */
    private final T two;

    /**
     * @param one le premier élément
     * @param two le second élément
     */
    public Couple(O one, T two) {
        Assert.notNull(one, "premier element obligatoire");
        Assert.notNull(two, "second element obligatoire");
        this.one = one;
        this.two = two;
    }

    public O getOne() {
        return one;
    }

    public T getTwo() {
        return two;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean equals(Object obj) {

        if (!(obj instanceof Couple)) {
            return false;
        }

        @SuppressWarnings("unchecked")
        Couple other = Couple.class.cast(obj);
        return ObjectUtils.equals(one, other.one) && ObjectUtils.equals(two, other.two);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public int hashCode() {
        return 31 * ObjectUtils.hashCode(one) + ObjectUtils.hashCode(two);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
    }
}
